const http = require('http')
const fs = require('fs')
const path = require('path')
const server = http.createServer(function(request, response) {
    const filePath = request.url

    if (/(jpg)$/i.test(filePath)) {
        response.writeHead(200, {
            'Content-Type': 'image/jpeg'
        })
    }

    if (/(js)$/i.test(filePath)) {
        response.writeHead(200, {
            'Content-Type': 'text/javascript; charset=utf-8'
        })
    }

    console.log(path.join(__dirname, filePath))
    fs.readFile(path.join(__dirname, filePath), function(err, data) {
        if (err) {
            response.end('File not found')
            return
        }
        setTimeout(() => {
            response.end(data);
        }, 10000)
    })

})

server.listen(3000)